package fy.hr.operator.impl;

import java.util.ArrayList;
import java.util.List;

import com.seeyon.v3x.services.flow.bean.FlowExport;

import fy.form.listen.operate.AForm_Save_Operator;
import fy.form.listen.operate.IFormOperator;
import fy.hr.bean.WorkOverTimeFormBean;
import fy.hr.dao.WorkOverTimeFormDao;
import fy.util.MyUtil;

public class WorkOverTimeFormOperator extends AForm_Save_Operator implements IFormOperator {
	private List<String> personCodeList = new ArrayList<String>();
	private List<String> overtimebegindayList = new ArrayList<String>();
	private List<String> overtimeenddayList = new ArrayList<String>();
	  private List<String> overtimesumhourList = new ArrayList<String>();
	 private List<String> reasonList = new ArrayList<String>(); 
	 private List<String> overtimetypeList = new ArrayList<String>();
	 private   List<String> remarkList = new ArrayList<String>();
	 

	private WorkOverTimeFormBean bean = new WorkOverTimeFormBean();

	// private List<String> personCodeList = new ArrayList<String>();//暂时不写多个
	public String getFormName() {
		return "加班加点申请单";
	}

	@Override
	protected void parseOtherField_FirstStep(FlowExport flowExport) {
		bean.setSummaryId(super.formBean.getSummaryId());

		bean.setBillname(flowExport.getFlowTitle());

		bean.setApplier(flowExport.getFlowCreatePerson().getName());

		bean.setTs(flowExport.getFlowCreateTime());

	}

	@Override
	protected void parseValueExport(com.seeyon.v3x.services.form.bean.ValueExport ve) {
		// TODO Auto-generated method stub
		String fieldName = ve.getDisplayName();
		String value = ve.getValue();
		/*
		 * private String overtimeid;//单据编号 加班单编码（主表） private String
		 * pk_corp;//公司名称 private String applydate;//申请日期 private String
		 * applydept;//部门/车间 private String psncode;//工号 private String
		 * applier;//姓名 private String overtimebeginday;// 加班时间起日期 private
		 * String overtimebegintime;// 加班时间起时间 private String overtimeendday;//
		 * 加班时间止 日期 private String overtimeendtime;// 加班时间止 时间 private String
		 * overtimesumhour;//加班时间合计 private String reason;//加班原因 private String
		 * overtimetype;//是否国家法定节假日(可能存的是ID值) private String remark;//备注
		 * 
		 * private String ts; private String billname; private long summaryId;
		 * private List<String> personCodeList = new ArrayList<String>();
		 * private List<String> overtimebegindayList = new ArrayList<String>();
		 * private List<String> overtimeenddayList = new ArrayList<String>();
		 * private List<String> overtimesumhourList = new ArrayList<String>();
		 * private List<String> reasonList = new ArrayList<String>(); private
		 * List<String> overtimetypeList = new ArrayList<String>(); private
		 * List<String> remarkList = new ArrayList<String>();
		 */
		if ("单据编号".equals(fieldName)) {
			bean.setOvertimeid(ve.getValue());
		} else if ("公司名称".equals(fieldName)) {
			bean.setPk_corp(value);
		} else if ("申请日期".equals(fieldName)) {
			bean.setApplydate(value);
		} else if ("工号".equals(fieldName)) {
			bean.setPsncode(value);
			this.personCodeList.add(ve.getValue());
		} else if ("姓名".equals(fieldName)) {
			bean.setApplier(value);
	/*	测试} else if ("部门车间".equals(fieldName)) {
			bean.setApplydept(value);*/
		} else if ("岗位".equals(fieldName)) {
			bean.setApplydept(value);
			/*//测试 } else if ("加班时间始".equals(fieldName)) {
			//bean.setOvertimebeginday(value);
			 this.overtimebegindayList.add(ve.getValue());
		} else if ("加班时间讫".equals(fieldName)) {
			//bean.setOvertimeendday(value);
			this.overtimeenddayList.add(ve.getValue());*/
		} else if ("时间起".equals(fieldName)) {
			//bean.setOvertimebeginday(value);
			 this.overtimebegindayList.add(ve.getValue());
		} else if ("时间止".equals(fieldName)) {
			//bean.setOvertimeendday(value);
			this.overtimeenddayList.add(ve.getValue());
		} else if ("合计".equals(fieldName)) {
			//bean.setOvertimesumhour(value);
			 this.overtimesumhourList.add(ve.getValue());
		} else if ("加班原因".equals(fieldName)) {
			//bean.setReason(value);
			this.reasonList.add(ve.getValue());
		} else if ("加班分类".equals(fieldName)) {
			//bean.setOvertimetype(value);
		 this.overtimetypeList.add(ve.getValue());
		} else if ("备注".equals(fieldName)) {
			//bean.setRemark(value);
			this.remarkList.add(ve.getValue());
		}

	}

	public boolean save() {
		// TODO Auto-generated method stub

		bean.setPersonCodeList(this.personCodeList);
		//System.out.println("~~~~~~~~~~~~~~~~~~!!"+personCodeList.size());
/*		for(int i=0;personCodeList.size()>i;i++){
		System.out.println("~~~~~~~~~~~~~~~~~~!!"+this.personCodeList.get(i));}*/
		bean.setOvertimebegindayList(this.overtimebegindayList);
		bean.setOvertimeenddayList(this.overtimeenddayList);
		bean.setOvertimesumhourList(this.overtimesumhourList);
		bean.setReasonList(this.reasonList);
	    bean.setOvertimetypeList(this.overtimetypeList);
		bean.setRemarkList(this.remarkList);
		WorkOverTimeFormDao wtf = new WorkOverTimeFormDao();
		wtf.setWorkOverTimeFormBean(bean);
		try {
		//	System.out.println("~~~~~~~~~~~~~" + 2);
			return wtf.InsertHR();
		} catch (Exception e) {
			e.printStackTrace();
		}
		/*
		 * if (personCodeList != null) personCodeList.clear(); personCodeList =
		 * null;
		 */
		return false;

	}

}
